package no.progark.golf.activities;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import no.progark.golf.Golf;
import no.progark.golf.Player;
import no.progark.golf.R;
import android.app.ListActivity;
import android.os.Bundle;
import android.widget.ListView;
import android.widget.SimpleAdapter;

public class ScoreBoardActivity extends ListActivity {
	Golf game = Golf.getInstance();
	ListView lv;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.scoreboard);
		lv = getListView();
		
//		Player[] players = (Player[]) game.getPlayerList().toArray();
		
		Player[] players = new Player[game.getPlayerList().size()];
		for (int i = 0; i < players.length; i++) {
			players[i] = game.getPlayerList().get(i);
		}
		
		
//		Player playerOne = new Player("Player one");
//		playerOne.setTotalScore(20);
//		playerOne.setShots(2);
//		
//		Player playerTwo = new Player("Player two");
//		playerTwo.setTotalScore(15);
//		playerTwo.setShots(3);
//		
//		Player playerThree = new Player("Player three");
//		playerThree.setTotalScore(25);
//		playerThree.setShots(6);
		
//		Player[] players = {playerOne, playerTwo, playerThree};
		
        String[] keys = new String[] {"Rank", "Name", "Score", "Shots"};
        int[] fields = new int[] {R.id.RANK_CELL, R.id.NAME_CELL, R.id.SCORE_CELL, R.id.SHOTS_CELL};

        // prepare the list of all records
        List<HashMap<String, String>> fillMaps = new ArrayList<HashMap<String, String>>();
        for (int i = 0; i < players.length; i++) {
        	HashMap<String, String> map = new HashMap<String, String>();
        	map.put("Rank", "" + (i + 1));
        	map.put("Name", "" + players[i].getName());
        	map.put("Score", "" + players[i].getTotalScore());
        	map.put("Shots", "" + players[i].getShots());
        	fillMaps.add(map);
        }

        SimpleAdapter adapter = new SimpleAdapter(this, fillMaps, R.layout.row, keys, fields);
        lv.setAdapter(adapter);
	}
}